<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台管理模板</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
		<link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
		<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
	</head>
	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo" ></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div class="title">快递员申请列表</div>
				<hr />
				<div class="select">
					<select lay-verify="" id="approvalSelectChange">
						<option value="">排序</option>
						<option value="1">最近使用↑</option>
						<option value="1">最近使用↓</option>
						<option value="2">信誉分↑</option>
						<option value="3">信誉分↓</option>
						<option value="4">按注册时间↑</option>
						<option value="4">按注册时间↓</option>
					</select>
				</div>
				<div class="layui-form">
					<table class="layui-table" id="approvalTable">
						<thead>
							<tr>
								<th><input type="checkbox" name="approvalcheck" id="checkall" onchange="checkAll(this,'#approvalTable')"></th>
								<th>头像</th>
								<th>手机号</th>
								<th>用户名</th>
								<th>真实姓名</th>
								<th>身份证号</th>
								<th>身份证正面照</th>
								<th>身份证背面照</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td><input type="checkbox" name="approvalcheck" id="" ></td>
								<td><img src="../../images/0.jpg"></td>
								<td>15967171111</td>
								<td>嘿嘿嘿嘿</td>
								<td>zyzy</td>
								<td>33031234</td>
								<td><a href="">点击查看</a></td>
								<td><a href="">点击查看</a></td>
								<td><div class="layui-btn  layui-btn-small pass">通过</div><div class="layui-btn layui-btn-danger  layui-btn-small turndown">驳回</div></td>
							</tr>
							<tr>
								<td><input type="checkbox" name="approvalcheck" id="" ></td>
								<td><img src="../../images/1.jpg"></td>
								<td>15967171111</td>
								<td>啦啦啦啦</td>
								<td>zyzy</td>
								<td>33031234</td>
								<td><a href="">点击查看</a></td>
								<td><a href="">点击查看</a></td>
								<td><div class="layui-btn  layui-btn-small pass">通过</div><div class="layui-btn layui-btn-danger  layui-btn-small turndown">驳回</div></td>
							</tr>
							<tr>
								<td><input type="checkbox" name="approvalcheck" id="" ></td>
								<td><img src="../../images/xiaosong.jpg"></td>
								<td>15967171111</td>
								<td>嘿嘿嘿嘿</td>
								<td>zyzy</td>
								<td>33031234</td>
								<td><a href="">点击查看</a></td>
								<td><a href="">点击查看</a></td>
								<td><div class="layui-btn  layui-btn-small pass">通过</div><div class="layui-btn layui-btn-danger  layui-btn-small turndown">驳回</div></td>
							</tr>
						</tbody>
					</table>
					<div class="layui-btn  layui-btn-small closeall" id="passall">批量通过</div>
				</div>
			</div>
			<!--底部导航-->
			<div class="layui-footer footer footer-demo" id="admin-footer"></div>
			<!--JS模块-->
			<script type="text/javascript" src="../../layui/layui.js"></script>
			<script src="../../js/jquery-1.12.3.min.js"></script>
			<script src="../../js/index.js"></script>
			<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
			<!-- DataTables JavaScript -->
			<script src="../../datatables/media/js/jquery.dataTables.min.js"></script>
			<script>
            var data = {
                "code": 200,
                "couriers": [{
                    "userId": 123456,
                    "courierId": 11111,
                    "headPortraitUrl": "../../images/xiaosong.jpg",
                    "nickname": "大灰狼",
                    "readName": "czl",
                    "username": "15967179999",
                    "idCardDown": "../../images/yuan_yellow.png",
                    "idCardUp": "../../images/yuan_yellow.png",
                    "idCardNo": "33032454545454",
                    "sex": "男",
                },{
                    "userId": 4652,
                    "courierId": 55555,
                    "headPortraitUrl": "../../images/fems.jpg",
                    "nickname": "小白兔",
                    "readName": "wjn",
                    "username": "15898989888",
                    "idCardDown": "../../images/yuan_yellow.png",
                    "idCardUp": "../../images/yuan_yellow.png",
                    "idCardNo": "33032454545454",
                    "sex": "女",
                },{
                    "userId": 9999,
                    "courierId": 66666,
                    "headPortraitUrl": "../../images/jn.jpg",
                    "nickname": "没烦恼",
                    "readName": "zylin",
                    "username": "15896765412",
                    "idCardDown": "../../images/yuan_yellow.png",
                    "idCardUp": "../../images/yuan_yellow.png",
                    "idCardNo": "33032454545454",
                    "sex": "男",
                }]
            }
            var table
			$(function() {
				$("#expressapproval").addClass('layui-this'); //对应订单管理的背景色
				table = $('#approvalTable').DataTable({
					responsive: true,
					ordering: false,
					searching: true,
					"bLengthChange": false,
					"bRetrieve": true,
					"bFilter": true //过滤功能
				});
                approvalSelectChange(1)
				adminCookie()
			})




            $(document).on('click', '.turndown', function() {
            	k = $(this).parents("tr").index();
            	var expressNickname = $(this).parents("tr").children('td:nth-child(3)').text()
                var element = this
            	layui.use('layer', function() {
            		var layer = layui.layer;
            		layer.confirm('是否要驳回用户：' + expressNickname + "?", {
            			icon: 2,
            			title: '提示'
            		}, function(index) {
            			/* $.ajax({
                                type: "DELETE",
                                url: "/randomdelivery/AdminController/courier/notPass/" + element.id,
                                data: {},
                                async: true,
                                dataType: "json",
                                contentType: "application/json",
                                success: function(data) {*/
            			if (data.code == 200) {
            			 table.row("tr:eq(" + k + ")").remove().draw( false );
                         layer.close(index);
                        }
                        /*},
                            Error: function() {
                                alert("服务器出错");
                            }
                        });*/
            		});

            	});
            })



            $(document).on('click', '.pass', function() {
                k = $(this).parents("tr").index();
                var expressNickname = $(this).parents("tr").children('td:nth-child(3)').text()
                var element = this
                layui.use('layer', function() {
                    var layer = layui.layer;
                    layer.confirm('是否要通过用户：' + expressNickname + "?", {
                        icon: 1,
                        title: '提示'
                    }, function(index) {
                        alert(element.id)
                        /* $.ajax({
                     type: "get",
                     url: "/randomdelivery/AdminController/courier/pass/"+element.id,
                     data: {},
                     async: true,
                     dataType: "json",
                     contentType: "application/json",
                     success: function(data) {*/
                        if (data.code==200) {
                        table.row("tr:eq(" + k + ")").remove().draw(false);
                        layer.close(index)
                    };
                     /*},
                     Error: function() {
                         alert("服务器出错");
                     }
                 })*/
                    });

                });
            })


            $("#passall").on('click', function() {
                if ($("input[name='approvalcheck']:checked").length == 0) {
                    layer.msg("请选择快递员")
                } else {
                    layui.use('layer', function() {
                        var layer = layui.layer;
                        layer.confirm('是否要通过选中用户？', {
                            icon: 1,
                            title: '提示'
                        }, function(index) {
                            $("input[name='approvalcheck']:checked").each(function() {
                                /* $.ajax({
                                     type: "get",
                                     url: "/randomdelivery/AdminController/courier/pass/"+element.id,
                                     data: {},
                                     async: true,
                                     dataType: "json",
                                     contentType: "application/json",
                                     success: function(data) {*/
                                            m = $(this).parents("tr").index();
                                            table.row("tr:eq(" + m + ")").remove().draw(false);
                                                /*},
                                     Error: function() {
                                         alert("服务器出错");
                                     }
                                 })*/
                                layer.close(index);
                            });

                        });
                    });
                }
            });

             $(document).on('click', 'tr td:not(:first)', function() {
                if( $(this).siblings().first().children().is(':checked')==false){
                    $(this).siblings().first().children().prop("checked", true);
                } else {
                    $(this).siblings().first().children().prop("checked", false);
                }
             })

            $("#approvalSequence").bind("change", function() {
                approvalSelectChange($(this).val())
                alert(213)
            })

            function approvalSelectChange(v) {
                /* $.ajax({
                     type: "get",
                     url: "/randomdelivery/AdminContro/AdminController/couriers/approval",
                     data: {
                         "sequence": v,
                     },
                     async: true,
                     dataType: "json",
                     contentType: "application/json",
                     success: function(data) {
    
                     },
                     Error: function() {
                         alert("服务器出错");
                     }
                 })*/
                approvaldata(data);
            }

            function approvaldata(data) {
                $('#approvalTable').dataTable().fnClearTable(); //清除表格内
                $.each(data.couriers, function(index, item) {
                    $('#approvalTable').dataTable().fnAddData([
                        '<input type="checkbox" name="approvalcheck"  >',
                        '<img src=' + item.headPortraitUrl + '>',
                        item.username,
                        item.nickname,
                        item.readName,
                        item.idCardNo,
                        '<a href="#">点击查看</a>',
                        '<a href="#">点击查看</a>',
                        // item.idCardUp,
                        // item.idCardDown,
                        '<div class="layui-btn  layui-btn-small pass" id="'+item.courierId+'">通过</div><div class="layui-btn layui-btn-danger  layui-btn-small turndown" id="'+item.courierId+'">驳回</div>'
                    ]);
                })
            }
			</script>
			
		</div>
	</body>
</html>